package com.course.web.view;

import com.course.web.component.custom.ClassPlanGrid;
import com.course.web.page.AdminUI;
import com.vaadin.navigator.View;
import com.vaadin.navigator.ViewChangeListener;
import com.vaadin.spring.annotation.SpringView;
import com.vaadin.ui.CustomComponent;
import org.apache.commons.lang3.math.NumberUtils;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * Created by Justin on 2017/5/25.
 */
@SpringView(name = ClassPlanView.NAME, ui = AdminUI.class)
public class ClassPlanView extends CustomComponent implements View {
    public static final String NAME = "class-plan";

    private final ClassPlanGrid planGrid;

    @Autowired
    public ClassPlanView(ClassPlanGrid planGrid) {
        this.planGrid = planGrid;
        setCompositionRoot(planGrid);
        setSizeFull();
    }

    @Override
    public void enter(ViewChangeListener.ViewChangeEvent event) {
        String parameters = event.getParameters();
        int teacherId = NumberUtils.toInt(parameters);
        planGrid.enter(teacherId);
    }
}
